#include <stdio.h>
#include <stdlib.h>

static void test1(void)
{
	int arr[2][3] = {1,2,3,4,5,6};
	int i = 0,j = 0;
	int *p;
//(W)	p = arr; 指针 = 地址
	p =&arr[i][j];//p = *arr;
	printf("p = %p *p = %d\n",p,*p);
	printf("*(p+5):%d\n",*(p+5));

	printf("arr: %p     arr + 1:%p\n",arr,arr+1);

	for (i=0;i<2;i++)
	{
		for(j=0;j<3;j++)
		{
		//	printf("%d ",arr[i][j]);
			printf("%d ",*(*(arr+i)+j));
		}
		printf("\n");
	}
}


/*
 *整形指针
 * */
static void test2(void)
{
	int arr[2][3] = {6,5,4,3,2,1};
	int i = 0;
	int *p;
	
	p = *arr;

	for (i=0;i<6;i++/*,p++*/)
	{
		printf("%d ",*(p+i));
//		printf("%d",*p);

	}
	printf("\n");
}
/*
 *数组指针
 * */
static void test2_1(void)
{
	int arr[2][3] = {1,2,3,4,5,6};
	int i = 0,j = 0;
//	数组指针 p变量  arr常量 
	int (*p) [3];
	p = arr;
	
	printf("arr:%p	arr+1:%p\n",arr,arr+1);	

	printf(" p :  %p \n",p);
	printf(" (p+1) : %p \n",p+1);
	

	
	for (i=0;i<2;i++)
	{
		for (j = 0;j<3;j++)
		{
		printf("%p-->%d\n",(p+i),*(*(p+i)+j));
		}
	}
}
/*
 *指针数组
 * */
static void test3(void)
{
	char *name[5] = {"Follow me","Basic","Great","Fortran","Computer"};
	int i = 0,j = 0,k = 0;
	char *temp;
#if 0
	//选择法
	for(i = 0;i<5-1;i++)
	{
		k = i;
		for(j = i+1;j<5;j++)
		{
			if (strcmp(name[k],name[j])>0)
			{
				k = j;
			}
		
		}
		if (k != j)
		{
			temp = name[i];
			name[i] = name[k];
			name[k] = temp;
		}

	}
#endif
	//冒泡
	for (i=0;i<5-1;i++)
	{
		for (j=0;j<5-1-i;j++)
		{
			if(strcmp(name[j],name[j+1])>0)
			{
				temp = name[j];
				name[j] = name[j+1];
				name[j+1] = temp;
			}

		}

	}


	for (i = 0; i < 5; i++)
	{
		puts(*(name+i));

	}

}


int main (void)
{
//	test1();
//	test2();
	test2_1();
	test3();
	exit(0);
}
